package sg.edu.nus.iss.vmcs.entity;

/*
 * Copyright 2003 ISS.
 * The contents contained in this document may not be reproduced in any
 * form or by any means, without the written permission of ISS, other
 * than for the purpose for which it has been supplied.
 *
 */



public class CashStore extends Store {

	public final static int INVALID_COIN_WEIGHT = 9999;

	public CashStore() {
	}
	
	public int findCashStoreIndex (Coin c) {
		int size = getStoreSize();
		for (int i = 0; i < size; i++) {
			StoreItem item = (CashStoreItem) getStoreItem(i);
			Coin current = (Coin) item.getContent();
			if (current.getWeight() == c.getWeight())
				return i;
		}
		return -1;
	}

	/**
	 * @param weight the weight of the coin
	 * @return a Coin object if the weight is valid
	 * return a null value if the weight does not match any of the Coins' weight in the CashStore 
	 */
	public Coin findCoin(double weight){
		StoreItem[] storeItems = getItems();
		if (storeItems == null)
			return null;
		
		for (int i = 0; i < storeItems.length; i++){
			Coin coin = (Coin) storeItems[i].getContent();
			if (coin.getWeight() == weight)
				return coin;
		}
		return null;
	}
	

}

